<template>
  <div style="width: 96%;margin: 0 auto">
    <div class="search">
      <div style="margin-left: 16px;margin-top: 10px;">
        <i class="el-icon-s-custom" ></i>
        患者管理
      </div>
      <div class="int">
        <el-form :model="queryParams" ref="queryForm" :inline="true"  label-width="68px">
          <el-form-item label="" prop="userName">
              <input type="text"  placeholder="请输入患者姓名"  v-model="queryParams.custName">
          </el-form-item>
        <el-select v-model="queryParams.sex" placeholder="请选择患者性别" style="margin-left: 20px;width: 225px;"  size="small">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>

        <input type="text"  placeholder="请输入证件号码" v-model="queryParams.certNo">

        <input type="text"  placeholder="请输入手机号" v-model="queryParams.phone">
<!--        <el-date-picker-->
<!--          style="width: 225px;height: 30px!important;margin-left: 20px;"-->
<!--          v-model="time"-->
<!--          size="small"-->
<!--          type="daterange"-->
<!--          range-separator=" "-->
<!--          start-placeholder="创建日期"-->
<!--          end-placeholder="">-->
<!--        </el-date-picker>-->
          <el-date-picker
            v-model="dateRange"
            size="small"
            style="width: 225px;margin-left: 20px;z-index: 10"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>

        </el-form>
      </div>
      <div class="inquire">
        <el-button type="success" style="height: 30px;display: flex;align-items: center;float:left;margin-right: 20px"
        @click="Querylist">
          <i  class="el-icon-search"></i>
          查询</el-button>
        <el-button style="height: 30px;display: flex;align-items: center;" @click="reset">
          <i  class="el-icon-refresh"></i>
          重置</el-button>
      </div>
    </div>
    <div class="list">
      <el-table
        :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
        stripe
        style="width: 100%"
        :row-class-name="tableRowClassName">
        <el-table-column
          prop="createTime"
          label="时间"
          align="center"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="custName"
          align="center"
          label="患者姓名"
          width="130">
        </el-table-column>
        <el-table-column
          prop="sex"
          label="性别"
          align="center"
          width="60">
        </el-table-column>
        <el-table-column
          prop="age"
          label="年龄"
          align="center"
          width="100">
        </el-table-column>
        <el-table-column
          prop="certNo"
          label="证件号码"
          align="center"
          width="180">
        </el-table-column>
        <el-table-column
          prop="phone"
          label="联系方式"
          align="center"
          width="180">
        </el-table-column>
        <el-table-column
          prop="address"
          align="center"
          label="联系地址">
        </el-table-column>
        <el-table-column
          prop="operate"
          align="center"
          label="操作">
          <template slot-scope="scope">
            <i class="el-icon-edit-outline" style="margin-left: 20px;color: #4196ff; cursor:pointer;" @click="editshow(scope.row)">编辑</i>
<!--            <i class="el-icon-success" style="margin-left: 20px;color: #1BD5B1; cursor:pointer;" @click="qi(scope.$index)"  v-show="enable">启用-->
<!--            </i>-->
            <i class="el-icon-success"
               style="margin-left: 20px;color: #1BD5B1; cursor:pointer;"
               @click="qi(scope.$index,scope.row)"  v-show="enable" >启用
            </i>
            <i class="el-icon-error" style="margin-left: 20px;color: #999999; cursor:pointer;" v-show= "forbidden"  @click="ji(scope.$index,scope.row)">禁用</i>
            <i class="el-icon-delete" style="margin-left: 20px; color: #FD3236; cursor:pointer;" @click="deletes(scope.$index,scope.row)">删除</i>
          </template>
        </el-table-column>
      </el-table>
      <div style="position: absolute;right: 40px;bottom: 70px;">
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="Querylist"
        />
      </div>
    </div>
    <div class="redact" v-show="fale">
      <div class="title">
        <div style="float:left;margin-left: 20px;margin-top: 10px">患者消息编辑</div>
        <div style="float:right;margin-top: 10px;margin-right: 20px" @click="editconceal">
          <i class="el-icon-close"></i>
        </div>
      </div>
      <el-form :label-position="labelPosition" :rules="rules" ref="formRef"  label-width="100px" :model="formLabelAlign" >
        <el-form-item label="患者姓名" prop="name" style="margin-top: 20px">
          <el-input class="txt" v-model="formLabelAlign.custName" style="width: 60%; height: 50px!important;"></el-input>
        </el-form-item>
        <el-form-item label="证件号码" prop="statusnumber">
          <el-input class="txt" v-model="formLabelAlign.certNo" maxlength="18" style="width: 50%; height: 50px!important;"></el-input>
        </el-form-item>
        <el-form-item label="职业" prop="statusnumber">
          <el-input class="txt" v-model="formLabelAlign.post" maxlength="18" style="width: 50%; height: 50px!important;"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input class="txt" v-model="formLabelAlign.phone" maxlength="11" style="width: 90%; height: 50px!important;"></el-input>
        </el-form-item>
        <el-form-item label="所在区域"  prop="area">
          <el-input class="txt" v-model="formLabelAlign.cityName" style="width: 90%; height: 50px!important;"></el-input>
        </el-form-item>
        <el-form-item label="详细住址"  prop="address">
          <el-input class="txt" v-model="formLabelAlign.address" style="width: 90%; height: 50px!important;"></el-input>
        </el-form-item>
        <p style="float:left;margin-left: 60px; margin-right: 20px; margin-top: -1px;">性别:</p>
        <el-radio v-model="formLabelAlign.sex" label="男">男</el-radio>
        <el-radio v-model="formLabelAlign.sex" label="女">女</el-radio>
        <el-radio v-model="formLabelAlign.sex" label="其他">其他</el-radio>
        <div style="margin-left: 35%;margin-top: 30px;">
          <div class="submit" @click="submit">提交</div>
          <div class="cancel" @click="editconceal">取消</div>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
  import {Querylist} from "../../api/patiente/patiente";
  import {sickadd} from "../../api/patiente/patiente";
  import {remove} from "../../api/patiente/patiente";
  import {area} from "../../api/patiente/patiente";

  export default {
    name: 'PatientManagement',
    data () {
      return {
        // 日期范围
        dateRange: [],

        patientgender: '',
        currentPage: 1,
        pagesize: 10,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          custName: undefined,
          certNo: undefined,
          phone: undefined
        },
        fale: false,
        // 总条数
        total: 0,
        enable:true,
        forbidden: false,
        labelPosition: 'right',
        options: [{
          value: '0',
          label: '男'
        }, {
          value: '1',
          label: '女'
        }, {
          value: '2',
          label: '其他'
        }],
        formLabelAlign: {},
        rules:{},
        // rules: {
        //   name: [
        //     { required: true, message: '请输入姓名', trigger: 'blur' },
        //     { min: 2, max: 4, message: '请输入正确姓名', trigger: 'blur' }
        //   ],
        //   age: [
        //     { required: true, message: '请输入年龄', trigger: 'blur' },
        //     // { pattern: /^(1[89])|([23]\d)|(4[0])$/, message: '请输入正18岁-40岁之间年龄', trigger: 'blur' }/^([1-9]\d?|1[01]\d|120)$/
        //     { pattern: /^([1-9]\d?|1[01]\d|120)$/, message: '请输入正1岁-120岁之间年龄', trigger: 'blur' }
        //   ],
        //   // sex: [
        //   //   { required: true, message: '请输入性别', trigger: 'blur' },
        //   //   { pattern: /^(男|女|保密)$/, message: '请输入正确性别', trigger: 'blur' }
        //   // ],
        //   // statusnumber: [
        //   //   { required: true, message: '请输入身份证', trigger: 'blur' },
        //   //   // { pattern: /^\d{17}[\dx]$/i, message: '请输入正确身份证', trigger: 'blur' }/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
        //   //   { pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, message: '请输入正确身份证', trigger: 'blur' }
        //   // ],
        //   phone: [
        //     { required: true, message: '请输入手机号', trigger: 'blur' },
        //     { pattern: /^1\d{10}$/, message: '请输入正确手机号', trigger: 'blur' }
        //   ]
        // },
        tableData: [{
          sex:''
        }]
      }
    },
    created(){
      this.Querylist()
      // this.area()
    },
    methods: {
      area(){
        area().then(res=>{
          console.log(res)
        }).catch(err=>{
          console.log(err)
        })
      },
      //患者查询
      // search(){
      //   Querylist(this.addDateRange(this.queryParams,this.dateRange)).then(res=>{
      //     console.log(res)
      //     this.tableData=res.rows;
      //     this.total = res.total;
      //     for (let i = 0 ; i<res.rows.length; i++){
      //       // console.log(res.rows[i].sex)
      //       if(res.rows[i].sex === '0'){
      //         res.rows[i].sex="男"
      //       }else if(res.rows[i].sex === '1'){
      //         res.rows[i].sex="女"
      //       }else if(res.rows[i].sex === '2'){
      //         res.rows[i].sex="其他"
      //       }
      //     }
      //   }).catch(err=>{
      //     console.log(err)
      //   })
      // },
      //患者列表/患者查询
      Querylist(){
        Querylist(this.addDateRange(this.queryParams,this.dateRange) ).then(res=>{
          console.log(res.rows)
          this.tableData=res.rows
          this.total =   res.total;
          for (let i = 0 ; i<res.rows.length; i++){
            // console.log(res.rows[i].sex)
            if(res.rows[i].sex === '0'){
              res.rows[i].sex="男"
            }else if(res.rows[i].sex === '1'){
              res.rows[i].sex="女"
            }else if(res.rows[i].sex === '2'){
              res.rows[i].sex="其他"
            }
          }
        }).catch(err=>{
          console.log(err)
        })
      },
      // 删除
      async deletes (index, row) {
          console.log(row.custId)
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          remove(row.custId).then(res => {
            console.log(res)
            this.Querylist()
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }).catch(err => {
            console.log(err)
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      // 重置
      reset () {
          this.dateRange=[],
          this.queryParams.custName='',
          this.queryParams.sex='',
          this.queryParams.certNo='',
          this.queryParams.phone='',
          this.Querylist()
      },
      // 分頁
      handleSizeChange (val) {
        this.pagesize = val
        console.log(`每页 ${val} 条`)
      },
      handleCurrentChange (val) {
        this.currentPage = val
        console.log(`当前页: ${val}`)
      },
      qi (index,row) {
        console.log(row)
        this.enable = false
        this.forbidden = true
      },
      ji (index,row) {
        console.log(row)
        this.forbidden = false
        this.enable = true
      },
      // 点击编辑
      editshow (row) {
        this.fale = true
        console.log(row)
        this.formLabelAlign = {...row}
        // this.formLabelAlign.custName = row.custName
        // this.formLabelAlign.phone = row.phone
        // this.formLabelAlign.certNo = row.certNo  //证件
        // this.formLabelAlign.area = row.address
        // this.formLabelAlign.address = row.address
        // this.formLabelAlign.sex = row.gender
      },
      submit(){
        sickadd(this.formLabelAlign).then(res=>{
          this.fale = false
          console.log(res)
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.Querylist()
          this.$refs.formRef.resetFields()
        }).catch(err=>{
          console.log(err)
        })
      },
      editconceal () {
        this.fale = false
        this.$refs.formRef.resetFields()
      },
      tableRowClassName ({ row, rowIndex }) {
        if (rowIndex === 1) {
          return 'warning-row'
        } else if (rowIndex === 3) {
          return 'success-row'
        }
        return ''
      }
    }
  }
</script>

<style scoped lang="scss">
  .submit{
    width: 80px;
    height: 30px;
    background: #009945;
    border-radius: 4px;
    color: #ffffff;
    text-align: center;
    line-height: 30px;
    font-size: 12px;
    float: left;
    cursor:pointer;
  }
  .cancel{
    width: 80px;
    float: left;
    height: 30px;
    border-radius: 4px;
    text-align: center;
    line-height: 30px;
    font-size: 12px;
    border: 1px solid #EEEEEE;
    margin-left: 20px;
    cursor:pointer;
  }
  .redact{
    width: 600px;
    height: 600px;
    background: #FFFFFF;
    box-shadow: 0px 0px 32px 0px rgba(97,97,97,0.1);
    border-radius: 8px;
    position:fixed;
    top: 50%;
    left: 50%;
    margin-left: -300px;
    margin-top: -285px;
    z-index: 10;
    .title{
      width: 100%;
      height: 40px;
      background: #e7e5e5;
      /*background:red;*/
      border-radius: 8px 8px 0px 0px;
    }
  }
  .search{
    width: 100%;
    height: 170px;
    background: #ffffff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0px 4px 20px 0px rgba(51,51,51,0.08);
    margin-top: 20px;
  }
  .list{
    width: 100%;
    height: 620px;
    background: #ffffff;
    box-shadow: 0px 4px 20px 0px rgba(51,51,51,0.08);
    border-radius: 8px;
    margin-top: 20px;
    overflow: hidden;
    /*.el-table .warning-row {*/
    /*  background: #fdf5e6;*/
    /*}*/

    /*.el-table .success-row {*/
    /*  background: #f0f9eb;*/
    /*}*/
  }
  .int{
    width: 75%;
    float: left;
    input{
      padding: 0px 10px;
      width: 225px;
      height: 30px;
      background: #FFFFFF;
      border: 1px solid #E8E8E8;
      border-radius: 4px;
      margin-left: 20px;
      margin-top:20px;
    }
  }
  .inquire{
    width: 20%;
    height: 50px;
    float: left;
    margin-top: 20px;
  }

</style>
